# -*- coding: utf-8 -*-

"""
# @version: v1.0
# @author : Wlis
# @Email : 19688513@qq.com
# @Project : py-stock_-app
# @File : stock_sh.py
# @Software: PyCharm
# @time: 2024/4/5 11:38
# @description : 上海股票模型类
"""
from service.models.stock_base import StockBase


class StockSh(StockBase):
    def __init__(self, _id, code, name, latest_price, change_percent, change_amount, volume, turnover, amplitude,
                 high, low, open_price, prev_close, volume_ratio, turnover_rate, dynamic_pe_ratio, pb_ratio,
                 total_market_value, circulating_market_value, increase_speed, five_minute_change, sixty_day_change,
                 year_to_date_change, creation_time, buy_volume=0, sell_volume=0, neutral_volume=0,
                 buy_amount=0.0, sell_amount=0.0, neutral_amount=0.0):
        """
        上海股票模型类
        (参数说明同前)
        """
        super().__init__(_id, code, name, latest_price, change_percent, change_amount, volume, turnover, amplitude,
                         high, low, open_price, prev_close, volume_ratio, turnover_rate, dynamic_pe_ratio, pb_ratio,
                         total_market_value, circulating_market_value, increase_speed, five_minute_change,
                         sixty_day_change, year_to_date_change, creation_time)

        # 初始化买盘、卖盘和中性盘的成交量和金额
        self._buy_volume = buy_volume
        self._sell_volume = sell_volume
        self._neutral_volume = neutral_volume
        self._buy_amount = buy_amount
        self._sell_amount = sell_amount
        self._neutral_amount = neutral_amount

    @property
    def buy_volume(self):
        return self._buy_volume

    @buy_volume.setter
    def buy_volume(self, value):
        if value < 0:
            raise ValueError("买盘成交量不能为负数")
        self._buy_volume = value

    @property
    def sell_volume(self):
        return self._sell_volume

    @sell_volume.setter
    def sell_volume(self, value):
        if value < 0:
            raise ValueError("卖盘成交量不能为负数")
        self._sell_volume = value

    @property
    def neutral_volume(self):
        return self._neutral_volume

    @neutral_volume.setter
    def neutral_volume(self, value):
        if value < 0:
            raise ValueError("中性盘成交量不能为负数")
        self._neutral_volume = value

    @property
    def buy_amount(self):
        return self._buy_amount

    @buy_amount.setter
    def buy_amount(self, value):
        if value < 0:
            raise ValueError("买盘成交金额不能为负数")
        self._buy_amount = value

    @property
    def sell_amount(self):
        return self._sell_amount

    @sell_amount.setter
    def sell_amount(self, value):
        if value < 0:
            raise ValueError("卖盘成交金额不能为负数")
        self._sell_amount = value

    @property
    def neutral_amount(self):
        return self._neutral_amount

    @neutral_amount.setter
    def neutral_amount(self, value):
        if value < 0:
            raise ValueError("中性盘成交金额不能为负数")
        self._neutral_amount = value

    def __str__(self):
        return (f"股票ID: {self.id}, 股票代码: {self.code}, 股票名称: {self.name}, "
                f"最新价格: {self.latest_price}, 涨跌幅: {self.change_percent}%, "
                f"涨跌额: {self.change_amount}, 成交量: {self.volume}, "
                f"成交额: {self.turnover}, 振幅: {self.amplitude}, "
                f"最高: {self.high}, 最低: {self.low}, 开盘价: {self.open_price}, "
                f"昨收: {self.prev_close}, 买盘成交量: {self.buy_volume}, "
                f"卖盘成交量: {self.sell_volume}, 中性盘成交量: {self.neutral_volume}, "
                f"买盘成交金额: {self.buy_amount}, 卖盘成交金额: {self.sell_amount}, "
                f"中性盘成交金额: {self.neutral_amount}, "
                f"量比: {self.volume_ratio}, 换手率: {self.turnover_rate}, "
                f"动态市盈率: {self.dynamic_pe_ratio}, 市净率: {self.pb_ratio}, "
                f"总市值: {self.total_market_value}, 流通市值: {self.circulating_market_value}, "
                f"涨速: {self.increase_speed}, 五分钟涨幅: {self.five_minute_change}, "
                f"六十天涨幅: {self.sixty_day_change}, 年初至今涨幅: {self.year_to_date_change}, "
                f"创建时间: {self.creation_time}")
